#按一个线的方向过滤
"""
金叉：2，死叉：-2  向上：1  向下：-1
支持重复计算，但是要指定timekey，只能向前重复计算
"""
from research.calcor.feather.ror_state import ror_state
class signal_filter_byfx:
    def __init__(self,timeperiod=1):
        self.roc_stat0=ror_state(timeperiod)
    def oncalc(self,s,l,timekey=None):
        if s is not None and l is not None:
            r=self.roc_stat0.oncalc(l,timekey)
            if r:
                if r>0 and s==2:
                    return s
                elif r<0 and s==-2:
                    return s
        return 0
